/*
# Rouleur Log - A log for cyclists.
# Copyright (C) 2006  Edward Copony (ecopony@gmail.com)
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package com.blazingredfireball.rouleurlog.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.blazingredfireball.rouleurlog.business.BikeDelegate;
	import com.blazingredfireball.rouleurlog.event.UpdateBikeEvent;
	import com.blazingredfireball.rouleurlog.model.RouleurlogModelLocator;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;

	public class UpdateBikeCommand extends BaseCommand implements ICommand, IResponder
	{
		[Bindable]
		private var model:RouleurlogModelLocator = RouleurlogModelLocator.getInstance();
		
		public function execute(event:CairngormEvent):void
		{
		  var delegate:BikeDelegate = new BikeDelegate(this);    
		  delegate.updateBike(model.selectedBike.id , UpdateBikeEvent(event).bike);
		}
		
		public function result(data:Object):void
		{
			new GetBikesCommand().execute(null);
		}
		
		public function fault(info:Object):void
		{
		  Alert.show("Bike could not be updated!");
		}
	}
}